#include "rtsp.h"
#include "rtsp_service.h"


int32_t vid_rtsp_init( rtsp_config *config, /*out*/VID_RTSP_HANDLE *handle ){
    int32_t ret = 0;
    vid_rtsp_ins *ins = new vid_rtsp_ins();
    ins->IVidRTSP = new RtspService();
    IVidRtsp* IVidrTSP = (IVidRtsp*)ins->IVidRTSP;
    if( ins->IVidRTSP == NULL ){
        return -1;
        printf( "get_instance failed\r\n" );
    }

    ret = IVidrTSP->init();
    if( ret < 0 ){
        printf( "vid_rtsp_init failed..............\r\n" );
        return -1;
    }

    *handle = (VID_RTSP_HANDLE)ins;
    return 0;
}


int32_t vid_rtsp_deinit( /*in*/VID_RTSP_HANDLE handle ){
    int32_t ret = 0;
    vid_rtsp_ins *ins = (vid_rtsp_ins*)handle;
    IVidRtsp* IVidrTSP = (IVidRtsp*)ins->IVidRTSP;

    if( ins == NULL || ins->IVidRTSP == NULL ){
        printf( "%s param Error....\r\n", __FUNCTION__ );
        return -1;
    }

    ret = IVidrTSP->deinit();
    if( ret < 0 ){
        printf( "vid_rtsp_deinit failed..............\r\n" );
        return -1;
    }
    delete IVidrTSP;
    delete ins;
    return ret;
}

int32_t vid_rtsp_start( /*in*/VID_RTSP_HANDLE handle){

    int32_t ret = 0;
    vid_rtsp_ins *ins = (vid_rtsp_ins*)handle;
    IVidRtsp* IVidrTSP = (IVidRtsp*)ins->IVidRTSP;

    if( ins == NULL || ins->IVidRTSP == NULL ){
        printf( "%s param Error....\r\n", __FUNCTION__ );
        return -1;
    }

    ret = IVidrTSP->start();
    if( ret < 0 ){
        printf( "vid_rtsp_start failed..............\r\n" );
        return -1;
    }
    return ret;
}


int32_t vid_rtsp_stop( /*in*/VID_RTSP_HANDLE handle ){

    int32_t ret = 0;
    vid_rtsp_ins *ins = (vid_rtsp_ins*)handle;
    IVidRtsp* IVidrTSP = (IVidRtsp*)ins->IVidRTSP;

    if( ins == NULL || ins->IVidRTSP == NULL ){
        printf( "%s param Error....\r\n", __FUNCTION__ );
        return -1;
    }
    ret = IVidrTSP->stop();
    if( ret < 0 ){
        printf( "vid_rtsp_stop failed\r\n" );
        return -1;
    }
    return ret;
}

int32_t vid_rtsp_deliver( /*in*/VID_RTSP_HANDLE handle, vidPacket *vid_pkg ){

    int32_t ret = 0;
    vid_rtsp_ins *ins = (vid_rtsp_ins*)handle;
    IVidRtsp* IVidrTSP = (IVidRtsp*)ins->IVidRTSP;
    if( ins == NULL || ins->IVidRTSP == NULL ){
        printf( "%s param Error....\r\n", __FUNCTION__ );
        return -1;
    }


    ret = IVidrTSP->deliver(vid_pkg);
    if( ret < 0 ){
        printf( "vid_rtsp_regcb failed\r\n" );
        return -1;
    }
    return ret;

}
